#include "stdafx.h"
#include "CusH264Struct.h"
#include<stdint.h>
#include<stdio.h>
#include<string.h>

#define SAFE_DELETE_ARRAY(obj) \
{   \
    if (obj != NULL)    \
    {   \
        delete[] obj;   \
        obj = NULL; \
    }   \
}

#define  SAFE_DELETE_OBJ(obj)   \
{   \
if (obj != NULL)    \
{   \
delete obj;   \
obj = NULL; \
}   \
}

CustH264Struct::CustH264Struct():
m_pbH264FrameData(NULL),
 m_iDataSize(0),
 m_iWidth(0),
 m_iHeight(0),
 m_isIFrame(0),
 m_isHistory(0),
m_llFrameTime(0),
index(0)
{

}

CustH264Struct::CustH264Struct(unsigned char* pbH264FrameData,
    unsigned long iDataSize,
    long iWidth,
    long iHeight,
    long isIFrame, 
    long IsHistory,
    unsigned long long FrameTime,int nindex):
    m_pbH264FrameData(NULL),
    m_iDataSize(iDataSize),
    m_iWidth(iWidth),
    m_iHeight(iHeight),
    m_isIFrame(isIFrame),
    m_isHistory(IsHistory),
    m_llFrameTime(FrameTime),
	index(nindex)
{
    if (pbH264FrameData != NULL
        && iDataSize > 0)
    {
        m_pbH264FrameData = new unsigned char[iDataSize];
        memcpy(m_pbH264FrameData, pbH264FrameData, iDataSize);
    }
}

CustH264Struct::CustH264Struct(const CustH264Struct &srcData)
{
    if(this == &srcData)
        return;

    m_iDataSize= srcData.m_iDataSize;
    m_iWidth= srcData.m_iWidth;
    m_iHeight= srcData.m_iHeight;
    m_isIFrame= srcData.m_isIFrame;
    m_isHistory= srcData.m_isHistory;
    m_llFrameTime= srcData.m_llFrameTime;
    index= srcData.index;

    if(srcData.m_iDataSize != 0 && srcData.m_pbH264FrameData != NULL)
    {
        m_pbH264FrameData = new unsigned char[srcData.m_iDataSize];
        if(m_pbH264FrameData != NULL )
        {
            memcpy(m_pbH264FrameData, srcData.m_pbH264FrameData,srcData.m_iDataSize );
        }
    }
}

CustH264Struct& CustH264Struct::operator =(const CustH264Struct &srcData)
{
    if(this == &srcData)
        return *this;

    m_iDataSize= srcData.m_iDataSize;
    m_iWidth= srcData.m_iWidth;
    m_iHeight= srcData.m_iHeight;
    m_isIFrame= srcData.m_isIFrame;
    m_isHistory= srcData.m_isHistory;
    m_llFrameTime= srcData.m_llFrameTime;
    index= srcData.index;

    if(m_pbH264FrameData != NULL)
    {
        SAFE_DELETE_ARRAY(m_pbH264FrameData);
    }

    if(srcData.m_iDataSize != 0 && srcData.m_pbH264FrameData != NULL)
    {
        m_pbH264FrameData = new unsigned char[srcData.m_iDataSize];
        if(m_pbH264FrameData != NULL )
        {
            memcpy(m_pbH264FrameData, srcData.m_pbH264FrameData,srcData.m_iDataSize );
        }
    }

    return *this;
}

CustH264Struct *CustH264Struct::copyData(CustH264Struct *pSrcData)
{
    if(pSrcData == NULL)
        return NULL;

    CustH264Struct* pDest = new CustH264Struct();
    if(pDest)
    {
        pDest->m_iDataSize= pSrcData->m_iDataSize;
        pDest->m_iWidth= pSrcData->m_iWidth;
        pDest->m_iHeight= pSrcData->m_iHeight;
        pDest->m_isIFrame= pSrcData->m_isIFrame;
        pDest->m_isHistory= pSrcData->m_isHistory;
        pDest->m_llFrameTime= pSrcData->m_llFrameTime;
        pDest->index= pSrcData->index;

        if(pSrcData->m_iDataSize != 0 && pSrcData->m_pbH264FrameData != NULL)
        {
            pDest->m_pbH264FrameData = new unsigned char[pSrcData->m_iDataSize];
            if(pDest->m_pbH264FrameData != NULL )
            {
                memcpy(pDest->m_pbH264FrameData, pSrcData->m_pbH264FrameData, pSrcData->m_iDataSize );
            }
        }
    }
    return pDest;
}

CustH264Struct::~CustH264Struct()
{
    SAFE_DELETE_ARRAY(m_pbH264FrameData);
}
